package LeetCode;

import java.util.Arrays;
import java.util.Comparator;

public class Bag_01 {
    private double max = 0;
    private void getMaxValue(Goods[] goodList) {
        Arrays.sort(goodList, Comparator.comparingDouble(
                (Goods goods) -> goods.value).reversed());
        double sum = 0;
        for (int i = 0; i < goodList.length; i++) {
            sum += goodList[i].weight;

            if (sum < max) {
                System.out.println(goodList[i].weight);
            } else {
                System.out.println(max - (sum - goodList[i].weight));
            }
        }

    }

}

class Goods {
    String name; //名称
    double weight;//重量
    double price;//价格
    double value;//价值

    public Goods(String name, double weight, double price) {
        this.name = name;
        this.weight = weight;
        this.price = price;
        this.value = price / weight;
    }
}
